import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:wch/constant/config_constant.dart';
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:wch/utils/log_utils.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../constant/resource_constant.dart';
//
//html 组件
//
class HtmlWidget extends StatefulWidget {
  final String url;
  final String title;

  const HtmlWidget(this.url, this.title, {Key? key}) : super(key: key);

  @override
  _HtmlWidgetState createState() => _HtmlWidgetState();
}

class _HtmlWidgetState extends State<HtmlWidget> {
  //是否加载完成
  bool isLoaded = false;
  bool isInitState = true;

  WebViewController? controller;
  @override
  void initState() {
    super.initState();



    // Timer(const Duration(milliseconds: 500), () {
    //   setState(() {
    //     isInitState = false;
    //   });
    // });

    controller = WebViewController(


    )
    // ..setNavigationDelegate(
    //     NavigationDelegate(
    //       onPageFinished: (String url) {
    //         LogUtils.log('onPageFinished url=$url');
    //         setState(() {
    //           Timer(Duration(seconds: 2), (){
    //             isLoaded = true;
    //           });
    //         });
    //       },
    //     )
    // )
    ..loadHtmlString(widget.title == '用户协议' ? agreementStr : privacyStr)
    ..setJavaScriptMode(JavaScriptMode.unrestricted);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          centerTitle: true,
          backgroundColor: themeBGC,
          foregroundColor: Colors.black,
        ),
        body:
        Container(
          color: Colors.black,
          child: ConstraintLayout(
            children: [
              WebViewWidget(controller: controller!
              ).applyConstraint(
                topLeftTo: parent,
                bottomRightTo: parent,
              ),
              // Offstage(
              //     offstage: isLoaded,
              //     child: Container(
              //         color: Colors.white
              //     )).applyConstraint(
              //   topLeftTo: parent,
              //   bottomRightTo: parent,
              // )
            ],
          ),
        ));
  }

}
